import { parse } from 'url';
import { TableListItem, TableListParams } from './data';

function getChargeRecords(
  req: { url: any },
  res: {
    json: (
      arg0: {
        body: {
          list: TableListItem[];
          count: number,
        }
      },
    ) => void;
  },
  u: any,
) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== '[object String]') {
    // eslint-disable-next-line prefer-destructuring
    url = req.url;
  }

  const params = (parse(url, true).query as unknown) as TableListParams;

  const dataSource: TableListItem[] = [];

  for (let i = (params.pageNum - 1) * 10; i < 10 * params.pageNum; i += 1) {
    dataSource.push({
      id: i + 1,
      parent_name: '张三丰',
      fcs_name: '张无忌',
      garden_name: '宏源小区',
      storage_type_desc: 1,
      storage_code: '1213414',
      exp_code: '12334566789876567898765',
      phone: '13333333333',
      total_amount: 12334500,
      sms_amount: 1234400,
      plat_service_amount: 130200,
      biz_type_desc: 1,
      biz_time: '2019-10-20',
    });
  }

  const result = {
    code: 0,
    body: {
      list: dataSource,
      count: 30,
    },
  };

  return res.json(result);
}

export default {
  'GET /consume/detail/index': getChargeRecords,
};
